package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.FeedbackPerson;
import com.huilai.platform.country_platform.model.InformationRecruitment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/3/3
 * 注释：
 */
public interface FeedbackPersonReposity extends JpaRepository<FeedbackPerson, Integer>, JpaSpecificationExecutor<FeedbackPerson> {
    FeedbackPerson findFeedbackPersonByNameAndPostcard(String name, String postcard);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into feedback_person(feedback_name, feedback_postcard, feedback_telephone, feedback_political, feedback_address, feedback_position, complaint_category, complaint_situation) " +
            "values(:#{#feedbackPerson.name}, :#{#feedbackPerson.postcard}, :#{#feedbackPerson.telephone}, :#{#feedbackPerson.political}, :#{#feedbackPerson.address}, :#{#feedbackPerson.position}, :#{#feedbackPerson.complaintCategory}, :#{#feedbackPerson.complaintSituation})", nativeQuery = true)
    Integer addFeedbackPerson(FeedbackPerson feedbackPerson);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update feedback_person fp set fp.feedback_name = :#{#feedbackPerson.name}, " +
            "fp.feedback_postcard = :#{#feedbackPerson.postcard}, " +
            "fp.feedback_telephone = :#{#feedbackPerson.telephone}, " +
            "fp.feedback_political = :#{#feedbackPerson.political}, " +
            "fp.feedback_address = :#{#feedbackPerson.address}, " +
            "fp.feedback_position = :#{#feedbackPerson.position}, " +
            "fp.complaint_category = :#{#feedbackPerson.complaintCategory}, " +
            "fp.complaint_situation = :#{#feedbackPerson.complaintSituation} where fp.id = :#{#feedbackPerson.id}",nativeQuery = true)
    Integer updateFeedbackPerson(FeedbackPerson feedbackPerson);

}
